home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / dflat_r_.arc / MOUSE.C < prev    next >
Text File  |  1991-10-02  |  2KB  |  98 lines

  1. /* ------------- mouse.c ------------- */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include "system.h"
  8.  
  9. static union REGS regs;
  10.  
  11. static void near mouse(int m1,int m2,int m3,int m4)
  12. {
  13.     regs.x.dx = m4;
  14.     regs.x.cx = m3;
  15.     regs.x.bx = m2;
  16.     regs.x.ax = m1;
  17.     int86(MOUSE, ®s, ®s);
  18. }
  19.  
  20. /* ---------- reset the mouse ---------- */
  21. void resetmouse(void)
  22. {
  23.     mouse(0,0,0,0);
  24. }
  25.  
  26. /* ----- test to see if the mouse driver is installed ----- */
  27. int mouse_installed(void)
  28. {
  29.     unsigned char far *ms;
  30.     ms = MK_FP(peek(0, MOUSE*4+2), peek(0, MOUSE*4));
  31.     return (SCREENWIDTH <= 80 && ms != NULL && *ms != 0xcf);
  32. }
  33.  
  34. /* ------ return true if mouse buttons are pressed ------- */
  35. int mousebuttons(void)
  36. {
  37.     if (mouse_installed())
  38.         mouse(3,0,0,0);
  39.     return regs.x.bx & 3;
  40. }
  41.  
  42. /* ---------- return mouse coordinates ---------- */
  43. void get_mouseposition(int *x, int *y)
  44. {
  45.     if (mouse_installed())    {
  46.         mouse(3,0,0,0);
  47.         *x = regs.x.cx/8;
  48.         *y = regs.x.dx/8;
  49.         if (SCREENWIDTH == 40)
  50.             *x /= 2;
  51.     }
  52. }
  53.  
  54. /* -------- position the mouse cursor -------- */
  55. void set_mouseposition(int x, int y)
  56. {
  57.     if (mouse_installed())    {
  58.         if (SCREENWIDTH == 40)
  59.             x *= 2;
  60.         mouse(4,0,x*8,y*8);
  61.     }
  62. }
  63.  
  64. /* --------- display the mouse cursor -------- */
  65. void show_mousecursor(void)
  66. {
  67.     if (mouse_installed())
  68.         mouse(1,0,0,0);
  69. }
  70.  
  71. /* --------- hide the mouse cursor ------- */
  72. void hide_mousecursor(void)
  73. {
  74.     if (mouse_installed())
  75.         mouse(2,0,0,0);
  76. }
  77.  
  78. /* --- return true if a mouse button has been released --- */
  79. int button_releases(void)
  80. {
  81.     if (mouse_installed())
  82.         mouse(6,0,0,0);
  83.     return regs.x.bx;
  84. }
  85.  
  86. /* ----- set mouse travel limits ------- */
  87. void set_mousetravel(int minx, int maxx, int miny, int maxy)
  88. {
  89.     if (mouse_installed())    {
  90.         if (SCREENWIDTH == 40)    {
  91.             minx *= 2;
  92.             maxx *= 2;
  93.         }
  94.         mouse(7, 0, minx*8, maxx*8);
  95.         mouse(8, 0, miny*8, maxy*8);
  96.     }
  97. }
  98.